package com.zzjson.observer;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Observable;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.observer</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月08日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class ObserverDemo {
	public static void main(String[] args) {
		MyObbservable observable = new MyObbservable() {
		};
		observable.addObserver((o, arg) -> System.out.println(arg));
		observable.setChanged();
		observable.notifyObservers("hello");
	}

	public static class MyObbservable extends Observable {
		@Override
		protected synchronized void setChanged() {
			super.setChanged();
		}
	}

	/**
	 * 拉的方式，通过循环去主动获取
	 */
	public static void echoIterable() {
		List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
		Iterator<Integer> iterator = integers.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}
	}
}